package mirrormonkey.core.tools.applications;

import mirrormonkey.core.client.ClientCoreModule;
import mirrormonkey.framework.ClientSyncAppState;

import com.jme3.app.SimpleApplication;
import com.jme3.network.Client;
import com.jme3.network.Network;
import com.jme3.system.AppSettings;
import com.jme3.system.JmeContext;

public class ClientTestApplication extends SimpleApplication {

	public final Client client;

	public final ClientSyncAppState appState;

	public final ClientCoreModule coreModule;

	public ClientTestApplication() throws Exception {
		setShowSettings(false);
		settings = new AppSettings(true);
		settings.setUseInput(false);

		client = Network.connectToServer("localhost", 10024);
		appState = new ClientSyncAppState(client);
		coreModule = appState.getModule(ClientCoreModule.class);
	}

	@Override
	public void start() {
		start(JmeContext.Type.Display);
	}

	@Override
	public void start(JmeContext.Type type) {
		client.start();
		super.start(type);
	}

	@Override
	public void stop() {
		client.close();
		super.stop(true);
		try {
			destroy();
		} catch (IllegalStateException e) {

		}
	}

	@Override
	public void simpleInitApp() {
		getStateManager().attach(appState);
	}

}